/*
 * @lc app=leetcode.cn id=367 lang=typescript
 *
 * [367] 有效的完全平方数
 */

// @lc code=start
function isPerfectSquare(num: number): boolean {
    if (num === 1) return true;

    let now = num;
    while (num > 1) {
        now = Math.ceil(now / 2);
        const result = now ** 2;
        if (result === num) return true;
        if (result < num) break;
    }
    while (now ** 2 < num) {
        now++;
    }

    return now ** 2 === num;
}
// @lc code=end
